define(function (required, exports, modules) {
  var modal = require("mods/modal");
  // exports.user_down = function(ols) {
  //   $("." + ols).dropdown({
  //     on: "hover"
  //   });
  // };
  exports.member_set = function () {

    $(".member-save").click(function () {
      if ($(this).hasClass("disabled")) {
        modal.alert("系统中在处理中~~~,请不要重复请求");
        return false;
      }

      var member_name = $("input[name=member-name]").val()
      var member_phone = $("input[name=member-phone]").val()
      var member_address = $("input[name=member-address]").val()
      var member_id = $("input[name=member-id]").val()
      var _csrf = $("#csrf").val();

      if (member_name.length < 1) {
        modal.msg("会员名称不能为空");
        return false;
      }

      if (member_address.length < 1) {
        modal.msg("请填写正确的会员地址");
        return false;
      }

      if (member_phone.length < 1 && !validatePhone(member_phone)) {
        modal.msg("请填写正确的电话号码");
        return false;
      }

      $(this).addClass("disabled");

      $.ajax({
        url: "/admin/member/set",
        type: "POST",
        dataType: "json",
        data: {
          member_name: member_name,
          member_phone: member_phone,
          member_address: member_address,
          member_id: member_id,
          _csrf: _csrf
        },
        success: function (res) {
          $(this).removeClass("disabled");
          if (res.code == 200) {
            modal.msg(res.msg, {}, function () {
              location.href = "/admin/member/index";
            });
          } else {
            modal.alert(res.msg);
            return false;
          }
        }
      });
    });
  };

  function validatePhone(phone) {
    //验证规则
    var isMobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;
    var isPhone = /^(?:(?:0\d{2,3})-)?(?:\d{7,8})(-(?:\d{3,}))?$/;
    //如果为1开头则验证手机号码
    if (mobile.substring(0, 1) == 1) {
      if (!isMobile.exec(mobile) && mobile.length != 11) {
        //错误提示信息
        return false;
      }
    }
    //否则全部不通过
    else {
      //错误提示信息
      return false;
    }
    return true;
  }

  // 验证身份证
  /*function isCardNo(card) {
    var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    return pattern.test(card);
  }*/
});
